// echo aux function only, should not compile alone.
// cp Utils.CS .. && cd $_ && for i in `\ls` ; do \cp -f Utils.CS $i/ ; done ; rm Utils.CS && cd "$OLDPWD"
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Collections.Generic;
using static Utils.Logger;
namespace Utils {
    public static class Logger {
        public static void logger(string s)=>GameData.Utilities.AdaptableLog.Info(s);
        public static void logwarn(string s)=>GameData.Utilities.AdaptableLog.Warning("<color=#FFFF00>"+s+"</color>",true);
        public static void logerror(string s)=>GameData.Utilities.AdaptableLog.Error(s); // should not use.
        public static void logex(Exception ex)=>logwarn(_strexception(ex,0)); // should not use.
        static string _strexception(Exception ex, int depth){
            var padding=depth==0?"\n":"\n"+new string(' ',depth*4);
            var content=("\n"+ex.GetType().Name+": "+ex.Message+"\n"+ex.StackTrace).Replace("\n",padding);
            if(ex.InnerException !=null){
                return content+_strexception(ex.InnerException,depth+1);
            } else {
                return content;
            }
        }
        public static unsafe byte* cpyi(byte* lhs, byte* rhs, int count, bool ptr_is_lhs){
            while(count>1){
                *(long*)lhs=*(long*)rhs;
                lhs+=8;rhs+=8;count-=2;
            }
            if(count==1){
                *(int*)lhs=*(int*)rhs;
                return (ptr_is_lhs?lhs:rhs)+4;
            } else {
                return ptr_is_lhs?lhs:rhs;
            }
        }
        public static unsafe byte* cpys(byte* lhs, byte* rhs, int count, bool ptr_is_lhs){
            while(count>3){
                *(long*)lhs=*(long*)rhs;
                lhs+=8;rhs+=8;count-=4;
            }
            if(count>1){
                *(int*)lhs=*(int*)rhs;
                lhs+=4;rhs+=4;count-=2;
            }
            if(count==1){
                *(short*)lhs=*(short*)rhs;
                return (ptr_is_lhs?lhs:rhs)+2;
            } else {
                return ptr_is_lhs?lhs:rhs;
            }
        }
    }
}
